#!/usr/bin/env python
# coding: utf-8

# In[2]:


import requests
import json

subscription_key = "0beb83e5382c49438d6f5cefc8938940"
assert subscription_key

face_api_url = 'https://fpkapi.cognitiveservices.azure.com/face/v1.0/detect'

image_url = 'http://newmedia.nfu.edu.cn/wcy/wp-content/uploads/2018/04/post_20180424__NFU_DoraHacks_imoji%E5%9B%A2%E9%98%9F.jpg' 

headers = {'Ocp-Apim-Subscription-Key': subscription_key}

params = {
    'returnFaceId': 'true',
    'returnFaceLandmarks': 'false',
    'returnFaceAttributes': 'age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise',
}

response = requests.post(face_api_url, params=params,
                         headers=headers, json={"url": image_url})


# In[3]:


json.dumps(response.json())


# In[4]:


results = response.json()
results


# In[7]:


import pandas as pd
df_face = pd.json_normalize(results)
df_face


# In[6]:


faceID = df_face['faceId'].values.tolist()
faceID 


# In[8]:


df_face.columns


# In[9]:


df_face[['faceId','faceAttributes.glasses','faceAttributes.emotion.neutral','faceAttributes.age','faceAttributes.gender']]


# In[ ]:




